package com.cloud.pole.shop.service.shops.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cloud.pole.api.advert.AdvertApi;
import com.cloud.pole.api.merchant.ShopMerchantInfoApi;
import com.cloud.pole.api.merchant.ShopMerchantUserApi;
import com.cloud.pole.api.param.PicklistApi;
import com.cloud.pole.api.user.BaseUserApi;
import com.cloud.pole.api.weixin.WxUserApi;
import com.cloud.pole.common.constant.CommonConstants;
import com.cloud.pole.common.constant.UserConstant;
import com.cloud.pole.common.exception.BaseException;
import com.cloud.pole.common.msg.ApiRestResponse;
import com.cloud.pole.common.util.jwt.IJWTInfo;
import com.cloud.pole.common.util.jwt.JWTInfo;
import com.cloud.pole.common.util.jwt.JwtTokenUtil;
import com.cloud.pole.feign.IAdvertService;
import com.cloud.pole.feign.IMerchantInfoService;
import com.cloud.pole.feign.IMerchantUserService;
import com.cloud.pole.feign.IParamPickListService;
import com.cloud.pole.feign.IUserService;
import com.cloud.pole.feign.IWeiXinService;
import com.cloud.pole.mapper.shops.ShopShopsMapper;
import com.cloud.pole.shop.biz.goods.ShopGoodsCategoryRecommBiz;
import com.cloud.pole.shop.biz.goods.ShopGoodsPromotionBiz;
import com.cloud.pole.shop.biz.shops.ShopShopsBiz;
import com.cloud.pole.shop.biz.shops.ShopShopsFansBiz;
import com.cloud.pole.shop.biz.shops.ShopShopsPayMethodBiz;
import com.cloud.pole.shop.biz.shops.ShopShopsPayTypeBiz;
import com.cloud.pole.shop.biz.shops.ShopShopsPayTypeStageNumBiz;
import com.cloud.pole.shop.biz.shops.ShopShopsQualificateBiz;
import com.cloud.pole.shop.biz.shops.ShopShopsUserBiz;
import com.cloud.pole.shop.biz.shops.ShopShopsViewBiz;
import com.cloud.pole.shop.biz.shops.ShopShopsViewLogBiz;
import com.cloud.pole.shop.constant.ShopCommonConstant;
import com.cloud.pole.shop.model.entity.goods.ShopGoodsCategoryRecommPos;
import com.cloud.pole.shop.model.entity.goods.ShopGoodsGroupRecomm;
import com.cloud.pole.shop.model.entity.order.ShopOrderItems;
import com.cloud.pole.shop.model.entity.shops.ShopMerchantInfo;
import com.cloud.pole.shop.model.entity.shops.ShopMerchantUser;
import com.cloud.pole.shop.model.entity.shops.ShopShops;
import com.cloud.pole.shop.model.entity.shops.ShopShopsAdmin;
import com.cloud.pole.shop.model.entity.shops.ShopShopsFans;
import com.cloud.pole.shop.model.entity.shops.ShopShopsPayMethod;
import com.cloud.pole.shop.model.entity.shops.ShopShopsPayType;
import com.cloud.pole.shop.model.entity.shops.ShopShopsPayTypeStageNum;
import com.cloud.pole.shop.model.entity.shops.ShopShopsQualificate;
import com.cloud.pole.shop.model.entity.shops.ShopShopsUser;
import com.cloud.pole.shop.model.entity.shops.ShopShopsView;
import com.cloud.pole.shop.model.entity.shops.ShopShopsViewLog;
import com.cloud.pole.shop.model.entity.shops.ShopShopsWithBLOBs;
import com.cloud.pole.shop.model.vo.goods.ShopGoodsCategoryRecommVo;
import com.cloud.pole.shop.model.vo.goods.ShopGoodsPromotionVo;
import com.cloud.pole.shop.model.vo.shops.MyShopVo;
import com.cloud.pole.shop.model.vo.shops.ShopIndexVo;
import com.cloud.pole.shop.model.vo.shops.ShopShopsVo;
import com.cloud.pole.shop.service.goods.GoodsGroupRecommService;
import com.cloud.pole.shop.service.shops.ShopShopsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/*
*2019年1月30日
*cloud-user
*author:frank-chen
*/
@Slf4j
@Service
public class ShopShopsServiceImpl implements ShopShopsService {
	@Autowired
	private ShopShopsBiz shopShopsBiz;
	@Autowired
	private IUserService userService;
	@Autowired
	private IWeiXinService weiXinService;
	@Autowired
	private ShopShopsQualificateBiz qualificateBiz;
	@Autowired
	private IAdvertService advertService;
	@Autowired
	private ShopGoodsPromotionBiz goodsPromotionBiz;
	@Autowired
	private ShopGoodsCategoryRecommBiz categoryRecommBiz;
	@Autowired
	private ShopShopsViewBiz viewBiz;
	@Autowired
	private ShopShopsFansBiz fansBiz;
	@Autowired
	private ShopShopsViewLogBiz viewLogBiz;
	@Autowired
	private ShopShopsUserBiz shopsUserBiz;
	@Autowired
	private IMerchantInfoService merchantInfoService;
	@Autowired
	private IMerchantUserService merchantUserService;
	@Autowired
	private ShopShopsPayMethodBiz shopShopsPayMethodBiz;
	@Autowired
	private ShopShopsPayTypeBiz shopShopsPayTypeBiz;
	@Autowired
	private IParamPickListService iParamPickListService;
	@Autowired
	private ShopShopsPayTypeStageNumBiz shopShopsPayTypeStageNumBiz;
	@Autowired
	private GoodsGroupRecommService goodsGroupRecommService;

	@Override
	public boolean checkShopsValid(ShopShopsWithBLOBs shopShops) throws Exception {
		// TODO Auto-generated method stub
		// 网店状态:-10关闭,0,新建,10开通
		if (shopShops == null) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "店铺不存在");
		}
		if (shopShops.getShopStatus() != ShopShops.SHOP_STATUS_OK) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "店铺无效");
		}
		if (shopShops.getShopPageStatus() != ShopShops.SHOP_PAGE_STATUS_OK) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "店铺无效");
		}
		return true;
	}

	@Override
	public Integer createShopWx(String banner, String shopName, String shopOwnerName, String mobileArea,
			String shopOwnerMobile, String openId) throws Exception {
		// TODO Auto-generated method stub
		// 查询微信信息
		ApiRestResponse<WxUserApi> wxUserResponse = weiXinService.getWxUser(openId);
		if (wxUserResponse.getStatus() != CommonConstants.STATUS_OK_CODE) {
			throw new BaseException(wxUserResponse.getStatus(), wxUserResponse.getMessage());
		}
		WxUserApi wxUserApi = wxUserResponse.getData();
		if (wxUserApi == null) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "请先保存用户资料");
		}
		// 检测是否已经创建过店铺（一个账号、一个店铺）
		ApiRestResponse<ShopMerchantUserApi> merchantUerResponse = merchantUserService.getUserByMobile(mobileArea,
				shopOwnerMobile);
		if (merchantUerResponse.getStatus() != CommonConstants.STATUS_OK_CODE) {
			throw new BaseException(merchantUerResponse.getStatus(), merchantUerResponse.getMessage());
		}
		ShopMerchantUserApi merchantUserApi = merchantUerResponse.getData();
		List<ShopShopsWithBLOBs> shopList = null;
		ShopMerchantInfoApi merchantInfoApi = null;
		if (merchantUserApi != null) {
			// 查询是否有店铺
			shopList = shopShopsBiz.selectListByMerchantId(merchantUserApi.getMerchantId());
			if (shopList != null && shopList.size() > 0) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "该手机创建过店铺");
			}
			ApiRestResponse<ShopMerchantInfoApi> merchantInfoResponse = merchantInfoService
					.getInfoById(merchantUserApi.getMerchantId());
			if (merchantInfoResponse.getStatus() != CommonConstants.STATUS_OK_CODE) {
				throw new BaseException(merchantInfoResponse.getStatus(), merchantInfoResponse.getMessage());
			}
			merchantInfoApi = merchantInfoResponse.getData();
		}
		// 检测是否已经注册会员
		ApiRestResponse<BaseUserApi> userResponse = userService.getUserByMobile(mobileArea, shopOwnerMobile);
		if (userResponse.getStatus() != CommonConstants.STATUS_OK_CODE) {
			throw new BaseException(userResponse.getStatus(), userResponse.getMessage());
		}
		// 已经是店铺
		BaseUserApi userApi = userResponse.getData();
		if (userApi != null && userApi.getUserType() == BaseUserApi.USER_TYPE_MERCHANT) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "该手机创建过店铺");
		}
		// 微信绑定
		userResponse = userService.wxUserBind(mobileArea, shopOwnerMobile, openId, BaseUserApi.USER_TYPE_MERCHANT);
		if (userResponse.getStatus() != CommonConstants.STATUS_OK_CODE) {
			throw new BaseException(userResponse.getStatus(), userResponse.getMessage());
		}
		userApi = userResponse.getData();
		// 创建商家
		if (merchantUserApi == null) {
			if (merchantInfoApi == null) {
				merchantInfoApi = new ShopMerchantInfoApi();
				merchantInfoApi.setCompanyName(shopName);
				merchantInfoApi.setMechantStatus(ShopMerchantInfo.MECHANT_STATUS_OK);
				merchantInfoApi.setContactMobile(shopOwnerMobile);
				merchantInfoApi.setContactName(shopOwnerName);
				ApiRestResponse<Integer> merchantInfoResponse = merchantInfoService.addMerchant(merchantInfoApi);
				if (merchantInfoResponse.getStatus() != CommonConstants.STATUS_OK_CODE) {
					throw new BaseException(merchantInfoResponse.getStatus(), merchantInfoResponse.getMessage());
				}
				// 设置商家id
				merchantInfoApi.setMerchantId(merchantInfoResponse.getData());
			}
			merchantUserApi = new ShopMerchantUserApi();
			merchantUserApi.setMerchantId(merchantInfoApi.getMerchantId());
			merchantUserApi.setUserId(userApi.getUserId());
			merchantUserApi.setUserName(mobileArea + shopOwnerMobile);
			merchantUserApi.setRealName(shopOwnerName);
			merchantUserApi.setSex(wxUserApi.getGender());
			merchantUserApi.setMobile(shopOwnerMobile);
			merchantUserApi.setMobileArea(mobileArea);
			merchantUserApi.setCreateTime(new Date());
			merchantUserApi.setUserStatus(ShopMerchantUser.USER_STATUS_OK);
			merchantUserApi.setNickName(wxUserApi.getNickName());
			merchantUserApi.setIconPath(wxUserApi.getAvatarUrl());

			merchantUserApi.setPassword(new BCryptPasswordEncoder(UserConstant.PW_ENCORDER_SALT)
					.encode(ShopCommonConstant.SHOP_MERCHANT_USER_DEFALUT_PWD));
			merchantUserApi.setRoleId(ShopCommonConstant.SHOP_MERCHANT_USER_ROLE_ID);

			ApiRestResponse<Long> merchantUserResponse = merchantUserService.addUser(merchantUserApi);
			if (merchantUserResponse.getStatus() != CommonConstants.STATUS_OK_CODE) {
				throw new BaseException(merchantUserResponse.getStatus(), merchantUserResponse.getMessage());
			}
			merchantUserApi.setUserId(merchantUserResponse.getData());

		}
		// 创建店铺
		if (shopList == null || shopList.size() == 0) {
			ShopShopsWithBLOBs shop = new ShopShopsWithBLOBs();
			shop.setMerchantId(merchantInfoApi.getMerchantId());
			shop.setShopName(shopName);
			shop.setLinkMan(shopOwnerName);
			shop.setMobile(shopOwnerMobile);
			shop.setShopStatus(ShopShops.SHOP_STATUS_OK);
			shop.setRecommendStatus(ShopShops.RECOMMEND_STATUS_NO);
			shop.setLogisticsArea(ShopShops.LOGISTICS_AREA_DEFAULT);
			shop.setShopPageStatus(ShopShops.SHOP_PAGE_STATUS_OK);
			shop.setBanner(banner);
			shop.setCreateUserId(merchantUserApi.getUserId().toString());
			shop.setCreateTime(new Date());
			shop.setCheckStatus(ShopShops.CHECK_STATUS_PASS);
			shop.setCheckTime(new Date());

			shopShopsBiz.insertUseGeneratedKeys(shop);
			// 生成店铺的二维码
			String strScene = "shopId=";
			strScene = strScene + Integer.toString(shop.getShopId());
			strScene = strScene + "&recommId=" + Long.toString(userApi.getUserId());
			log.info("生成店铺的二维码-" + strScene);

			ApiRestResponse<String> qrCodeResponse = weiXinService.getWxQrCodeUnlimit(wxUserApi.getWxAppId(), strScene,
					ShopCommonConstant.SHOP_QRCODE_PAGE);
			String strQrCode = null;
			if (qrCodeResponse != null && qrCodeResponse.getStatus() == CommonConstants.STATUS_OK_CODE) {
				strQrCode = qrCodeResponse.getData();
			}
			// 更新店铺二维码
			if (!StringUtils.isEmpty(strQrCode)) {
				shop.setQrcode(strQrCode);
				shopShopsBiz.updateSelectiveById(shop);
			}

			// 添加店铺原始数据
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("shopId", shop.getShopId());
			shopShopsBiz.addDefaultData(map);
			// Integer shopId = (Integer)map.get("shopId");
			// Integer resultState = (Integer)map.get("resultState");
			// String resultDesc = (String)map.get("resultDesc");
			log.info("添加店铺原始数据-" + map.toString());
			return shop.getShopId();
		}
		return null;
	}

	@Override
	public ShopIndexVo getIndexData(String token, Integer shopId, String openId, Long recommUserId) throws Exception {
		// TODO Auto-generated method stub
		// 如果是店主只能进自己的店铺
		Long userId = null;
		if (!StringUtils.isEmpty(token)) {
			IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
			userId = Long.parseLong(jwtInfo.getId());
			List<ShopShops> shopList = shopShopsBiz.selectListByManageUserId(userId, null);
			if (shopList != null && shopList.size() > 0) {
				shopId = shopList.get(0).getShopId();
			}
		}
		// 从最新访问的店铺获取
		if (shopId == null && userId != null) {
			ShopShopsView viewShop = getLastViewShop(token, openId);
			if (viewShop != null) {
				shopId = viewShop.getShopId();
			}
			// else {
			// throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "请扫码店主二维码进入店铺");
			// }
		}
		// 默认店铺
		if (shopId == null) {
			shopId = ShopCommonConstant.STORE_SHOP_DEFAULT_SHOP_ID;
		}
		ShopShopsWithBLOBs shopShops = shopShopsBiz.selectById(shopId);
		// 检测店铺是否有效
		checkShopsValid(shopShops);

		// 店铺资质
		List<ShopShopsQualificate> qualificateList = qualificateBiz.selectListByShopId(shopId,
				ShopShopsQualificate.QUALIFICATE_STATUS_OK);
		// 店铺轮播图
		ApiRestResponse<List<AdvertApi>> advertResponse = advertService.getShopAdvertList(shopId,
				ShopCommonConstant.STORE_SHOP_ADVERT_INDEX);
		if (advertResponse.getStatus() != CommonConstants.STATUS_OK_CODE) {
			throw new BaseException(advertResponse.getStatus(), advertResponse.getMessage());
		}
		List<AdvertApi> advertList = advertResponse.getData();
		// 推荐产品
		List<ShopGoodsPromotionVo> goodsRecommList = goodsPromotionBiz.selectShopGoodsPromotionVoListByMap(shopId,
				ShopCommonConstant.PROMOTION_TYPE_STORE_SHOP_INDEX);
		// 推荐栏目
		List<ShopGoodsCategoryRecommVo> categoryRecommList = categoryRecommBiz.selectListByShopId(shopId,
				ShopGoodsCategoryRecommPos.RECOMM_POS_ID_STORE_SHOP_INDEX);

		ShopIndexVo indexVo = new ShopIndexVo();
		// 是否为点赞或喜欢标志
		ShopShopsFans fans = fansBiz.selectByShopIdAndOpenId(shopId, openId);
		if (fans != null) {
			if (fans.getFansStatus().intValue() == ShopShopsFans.FANS_STATUS_YES) {
				indexVo.setFansFlag(true);
			} else {
				indexVo.setFansFlag(false);
			}
		}
		// 增加浏览量，后期需要放到rabbitMQ消息队列
		int addFlag = addViewAndQRCode(token, shopId, openId, recommUserId);
		if (addFlag == 1) {
			shopShops.setViewCount(shopShops.getViewCount() + addFlag);
		}

		// 粉丝
		List<ShopShopsView> viewList = viewBiz.selectTopListByShopId(shopId,
				ShopCommonConstant.STORE_SHOP_INDEX_VIEW_FANS);
		ShopShopsVo shopsVo = new ShopShopsVo();
		BeanUtils.copyProperties(shopShops, shopsVo);
		indexVo.setShopShopsVo(shopsVo);
		indexVo.setQualificateList(qualificateList);
		indexVo.setAdvertList(advertList);
		indexVo.setGoodsRecommList(goodsRecommList);
		indexVo.setCategoryRecommList(categoryRecommList);
		indexVo.setViewList(viewList);

		return indexVo;
	}

	@Override
	public int addViewAndQRCode(String token, Integer shopId, String openId, Long recommUserId) throws Exception {
		// TODO Auto-generated method stub
		int addFlag = 0;
		// 查询微信信息
		ApiRestResponse<WxUserApi> wxUserResponse = weiXinService.getWxUser(openId);
		if (wxUserResponse.getStatus() != CommonConstants.STATUS_OK_CODE) {
			throw new BaseException(wxUserResponse.getStatus(), wxUserResponse.getMessage());
		}
		WxUserApi wxUserApi = wxUserResponse.getData();
		if (wxUserApi == null) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "请先保存用户资料");
		}
		Long userId = null;
		if (!StringUtils.isEmpty(token)) {
			IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
			userId = Long.parseLong(jwtInfo.getId());
		}
		// 查询店铺信息
		ShopShopsWithBLOBs shopShops = shopShopsBiz.selectById(shopId);
		// 检测店铺是否有效
		checkShopsValid(shopShops);
		// 查询是否有记录
		ShopShopsView shopShopsView = viewBiz.selectByShopIdAndOpenId(shopId, openId);
		boolean blNewUser = false;
		if (shopShopsView == null) {
			blNewUser = true;
			shopShopsView = new ShopShopsView();
			shopShopsView.setShopId(shopId);
			shopShopsView.setMerchantId(shopShops.getMerchantId());
			shopShopsView.setLastViewTime(new Date());
			shopShopsView.setViewTimes(1);
			shopShopsView.setOpenId(openId);
			shopShopsView.setUserId(userId);
			shopShopsView.setAvatarUrl(wxUserApi.getAvatarUrl());
			shopShopsView.setNickName(wxUserApi.getNickName());
			shopShopsView.setShopName(shopShops.getShopName());
			viewBiz.insertSelective(shopShopsView);
		} else {
			shopShopsView.setViewTimes(shopShopsView.getViewTimes() + 1);
			shopShopsView.setLastViewTime(new Date());
			shopShopsView.setAvatarUrl(wxUserApi.getAvatarUrl());
			shopShopsView.setNickName(wxUserApi.getNickName());
			shopShopsView.setShopName(shopShops.getShopName());
			viewBiz.updateSelectiveById(shopShopsView);
		}
		// 更新店铺信息
		Long viewCount = 0L;
		if (blNewUser) {
			addFlag = 1;
			viewCount = shopShops.getViewCount().longValue() + 1;
			shopShops.setViewCount(viewCount);
			shopShopsBiz.updateSelectiveById(shopShops);
		}
		// 写入浏览日志
		ShopShopsViewLog viewLog = new ShopShopsViewLog();
		viewLog.setMerchantId(shopShops.getMerchantId());
		viewLog.setShopId(shopId);
		viewLog.setOpenId(openId);
		viewLog.setUserId(userId);
		viewLog.setViewNote("");
		viewLog.setViewTime(new Date());
		viewLog.setViewUrl("");
		viewLogBiz.insertSelective(viewLog);

		// 添加用户信息
		ShopShopsUser shopShopsUser = shopsUserBiz.selectByShopIdAndOpenId(shopId, openId);
		if (shopShopsUser == null) {
			// 生成店铺的二维码
			String strQrCode = null;
			if (userId != null) {
				String strScene = "shopId=" + Integer.toString(shopId);
				strScene = strScene + "&recommId=" + Long.toString(userId);
				log.info("生成用户店铺的二维码-" + strScene);
				ApiRestResponse<String> qrCodeResponse = weiXinService.getWxQrCodeUnlimit(wxUserApi.getWxAppId(),
						strScene, ShopCommonConstant.SHOP_QRCODE_PAGE);
				if (qrCodeResponse != null && qrCodeResponse.getStatus() == CommonConstants.STATUS_OK_CODE) {
					strQrCode = qrCodeResponse.getData();
				}
			}
			shopShopsUser = new ShopShopsUser();
			shopShopsUser.setCreateTime(new Date());
			shopShopsUser.setMerchantId(shopShops.getMerchantId());
			shopShopsUser.setOpenId(openId);
			if (!StringUtils.isEmpty(strQrCode)) {
				shopShopsUser.setQrcode(strQrCode);
			}
			shopShopsUser.setShopId(shopId);
			shopShopsUser.setUserId(userId);
			shopShopsUser.setWxUserId(wxUserApi.getWxUserId());
			if (shopShopsUser.getFirstRecommUserId() == null && recommUserId != null) {
				shopShopsUser.setFirstRecommUserId(recommUserId);
			}
			shopsUserBiz.insertSelective(shopShopsUser);
		} else {
			boolean hasModify = false;
			if (shopShopsUser.getFirstRecommUserId() == null && recommUserId != null) {
				shopShopsUser.setFirstRecommUserId(recommUserId);
				hasModify = true;
			}
			if (shopShopsUser.getUserId() == null && userId != null) {
				shopShopsUser.setUserId(userId);
				hasModify = true;
			}
			if (StringUtils.isEmpty(shopShopsUser.getQrcode())) {
				String strQrCode = null;
				if (userId != null) {
					String strScene = "shopId=" + Integer.toString(shopId);
					strScene = strScene + "&recommId=" + Long.toString(userId);
					log.info("生成用户店铺的二维码-" + strScene);
					ApiRestResponse<String> qrCodeResponse = weiXinService.getWxQrCodeUnlimit(wxUserApi.getWxAppId(),
							strScene, ShopCommonConstant.SHOP_QRCODE_PAGE);
					if (qrCodeResponse != null && qrCodeResponse.getStatus() == CommonConstants.STATUS_OK_CODE) {
						strQrCode = qrCodeResponse.getData();
						if (!StringUtils.isEmpty(strQrCode)) {
							shopShopsUser.setQrcode(strQrCode);
							hasModify = true;
						}
					}
				}
			}
			if (hasModify) {
				shopsUserBiz.updateSelectiveById(shopShopsUser);
			}
		}
		return addFlag;
	}

	@Override
	public Long modifyFansStatus(String token, Integer shopId, String openId, Integer fansStatus) throws Exception {
		// TODO Auto-generated method stub
		// 查询微信信息
		ApiRestResponse<WxUserApi> wxUserResponse = weiXinService.getWxUser(openId);
		if (wxUserResponse.getStatus() != CommonConstants.STATUS_OK_CODE) {
			throw new BaseException(wxUserResponse.getStatus(), wxUserResponse.getMessage());
		}
		WxUserApi wxUserApi = wxUserResponse.getData();
		if (wxUserApi == null) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "请先保存用户资料");
		}
		Long userId = null;
		if (!StringUtils.isEmpty(token)) {
			IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
			userId = Long.parseLong(jwtInfo.getId());
		}
		// 查询店铺信息
		ShopShopsWithBLOBs shopShops = shopShopsBiz.selectById(shopId);
		// 检测店铺是否有效
		checkShopsValid(shopShops);
		// 查询是否有记录
		ShopShopsFans shopShopsFans = fansBiz.selectByShopIdAndOpenId(shopId, openId);
		if (shopShopsFans == null && fansStatus.intValue() == ShopShopsFans.FANS_STATUS_NO) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "未点赞、不用取消点赞");
		}
		if (shopShopsFans != null && fansStatus.intValue() == shopShopsFans.getFansStatus().intValue()) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "不能重复操作");
		}
		if (shopShopsFans == null) {
			shopShopsFans = new ShopShopsFans();
			shopShopsFans.setShopId(shopId);
			shopShopsFans.setMerchantId(shopShops.getMerchantId());
			shopShopsFans.setFansStatus(fansStatus);
			shopShopsFans.setFansTime(new Date());
			shopShopsFans.setOpenId(openId);
			shopShopsFans.setUserId(userId);
			shopShopsFans.setNickName(wxUserApi.getNickName());
			shopShopsFans.setAvatarUrl(wxUserApi.getAvatarUrl());
			fansBiz.insertSelective(shopShopsFans);
		} else {
			log.info("fansStatus[" + fansStatus + "]");
			log.info("getShopId[" + shopShopsFans.getShopId() + "]");

			shopShopsFans.setFansStatus(fansStatus);
			shopShopsFans.setFansTime(new Date());
			shopShopsFans.setNickName(wxUserApi.getNickName());
			shopShopsFans.setAvatarUrl(wxUserApi.getAvatarUrl());
			fansBiz.updateSelectiveById(shopShopsFans);
		}
		// 更新店铺信息
		Long fansCount = 0L;
		if (fansStatus.intValue() == ShopShopsFans.FANS_STATUS_YES) {
			fansCount = shopShops.getFansCount().longValue() + 1;
			shopShops.setFansCount(fansCount);
		} else if (fansStatus.intValue() == ShopShopsFans.FANS_STATUS_NO) {
			fansCount = shopShops.getFansCount().longValue() - 1;
			shopShops.setFansCount(fansCount);
		}
		shopShopsBiz.updateSelectiveById(shopShops);
		return fansCount;
	}

	@Override
	public ShopShopsView getLastViewShop(String token, String openId) throws Exception {
		// TODO Auto-generated method stub
		if (!StringUtils.isEmpty(token)) {
			IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
			Long userId = Long.parseLong(jwtInfo.getId());
			return viewBiz.selectLastViewShop(userId, openId);
		}
		return null;
	}

	@Override
	public MyShopVo getMyShopInfo(String token) throws Exception {
		// TODO Auto-generated method stub
		IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
		Long userId = Long.parseLong(jwtInfo.getId());
		// 根据用户id查询店铺id
		List<ShopShops> shopList = shopShopsBiz.selectListByManageUserId(userId, null);
		if (shopList == null || shopList.size() == 0) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "还没有创建店铺");
		}
		ShopShops shopShops = shopList.get(0);

		// 店铺轮播图
		ApiRestResponse<List<AdvertApi>> advertResponse = advertService.getShopAdvertList(shopShops.getShopId(),
				ShopCommonConstant.STORE_SHOP_ADVERT_INDEX);
		if (advertResponse.getStatus() != CommonConstants.STATUS_OK_CODE) {
			throw new BaseException(advertResponse.getStatus(), advertResponse.getMessage());
		}
		List<AdvertApi> advertList = advertResponse.getData();

		MyShopVo myShopVo = new MyShopVo();
		ShopShopsWithBLOBs shopBlob = new ShopShopsWithBLOBs();
		BeanUtils.copyProperties(shopShops, shopBlob);
		myShopVo.setAdvertList(advertList);
		myShopVo.setShop(shopBlob);
		return myShopVo;
	}

	@Override
	public boolean modifyMyShop(String token, Integer shopId, String banner, String shopName, String shopOwnerName,
			String longitude, String latitude, String images, String provinceName, String cityName, String districtName,
			String address) throws Exception {
		// TODO Auto-generated method stub
		IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
		Long userId = Long.parseLong(jwtInfo.getId());
		// 根据用户id查询店铺id
		List<ShopShops> shopList = shopShopsBiz.selectListByManageUserId(userId, shopId);
		if (shopList == null || shopList.size() == 0) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "店铺id错误");
		}
		// 检测轮播图
		String[] array = images.split(",");
		if (array == null || array.length == 0) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "轮播图参数错误");
		}
		// 查询店铺信息
		ShopShopsWithBLOBs shopShops = shopShopsBiz.selectById(shopId);
		shopShops.setBanner(banner);
		shopShops.setShopName(shopName);
		shopShops.setLinkMan(shopOwnerName);
		shopShops.setLatitude(new Double(latitude));
		shopShops.setLongitude(new Double(longitude));
		shopShops.setAddress(address);
		shopShops.setProvinceName(provinceName);
		shopShops.setCityName(cityName);
		shopShops.setDistrictName(districtName);
		shopShopsBiz.updateSelectiveById(shopShops);

		// 修改轮播图
		List<String> advertList = new ArrayList<String>();
		for (int i = 0; i < array.length; i++) {
			if (!StringUtils.isEmpty(array[i])) {
				advertList.add(array[i]);
			}
		}
		advertService.modifyShopAdvertList(shopId, shopShops.getMerchantId(),
				ShopCommonConstant.STORE_SHOP_ADVERT_INDEX, advertList);
		return true;
	}

	@Override
	public PageInfo<ShopShopsView> getMyShopViewList(String token, Integer shopId, Integer pageSize, Integer pageNum)
			throws Exception {
		// TODO Auto-generated method stub
		IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
		Long userId = Long.parseLong(jwtInfo.getId());
		// 根据用户id查询店铺id
		List<ShopShops> shopList = shopShopsBiz.selectListByManageUserId(userId, shopId);
		if (shopList == null || shopList.size() == 0) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "店铺id错误");
		}
		PageHelper.startPage(pageNum, pageSize);
		List<ShopShopsView> list = viewBiz.selectListByShopId(shopId);
		PageInfo<ShopShopsView> pageInfo = new PageInfo<ShopShopsView>(list);
		return pageInfo;
	}

	@Override
	public String getWxUserQrCode(String token, Integer shopId, String openId) throws Exception {
		// TODO Auto-generated method stub
		ShopShopsUser shopsUser = shopsUserBiz.selectByShopIdAndOpenId(shopId, openId);
		if (shopsUser == null || StringUtils.isEmpty(shopsUser.getQrcode())) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "无推广二维码");
		}
		return shopsUser.getQrcode();
	}

	@Override
	public List<ShopShopsView> getUserViewShopList(String token, String openId) throws Exception {
		// TODO Auto-generated method stub
		return viewBiz.selectListByOpenId(openId);
	}

	@Override
	public Integer getMyShopId(String token) throws Exception {
		// TODO Auto-generated method stub
		IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
		Long userId = Long.parseLong(jwtInfo.getId());
		// 根据用户id查询店铺id
		List<ShopShops> shopList = shopShopsBiz.selectListByManageUserId(userId, null);
		if (shopList == null || shopList.size() == 0) {
			throw new BaseException(CommonConstants.STATUS_ERROR_CODE, "还没有创建店铺");
		}
		ShopShops shopShops = shopList.get(0);
		return shopShops.getShopId();
	}

	@Override
	public List<ShopShopsWithBLOBs> getAllShopList(String token) throws Exception {
		IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
		int userType = jwtInfo.getType();
		Example example = new Example(ShopShopsWithBLOBs.class);
		Criteria criteria = example.createCriteria();
		if (userType == JWTInfo.USER_TYPE_MERCHANTT) {
			Integer merchantId = Integer.parseInt(jwtInfo.getAttr1());
			criteria.andEqualTo("merchantId", merchantId);
		}
		example.setOrderByClause("shop_id");
		criteria.andEqualTo("shopStatus", ShopShopsWithBLOBs.SHOP_STATUS_OK);
		criteria.andEqualTo("checkStatus", ShopShopsWithBLOBs.CHECK_STATUS_PASS);
		return shopShopsBiz.selectByExample(example);
	}

	@Override
	public PageInfo<ShopShopsWithBLOBs> selectPageShopAdminList(String shopName, Integer pageNo, Integer pageSize)
			throws Exception {
		PageHelper.startPage(pageNo, pageSize);
		List<ShopShopsWithBLOBs> list = shopShopsBiz.selectPageShopAdminList(shopName);
		PageInfo<ShopShopsWithBLOBs> page = new PageInfo<ShopShopsWithBLOBs>(list);
		return page;
	}

	// 店铺添加
	@Override
	@Transactional
	public void addShopShops(String token, Map map) throws Exception {
		IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
		ShopShops shopShops = new ShopShops();// 店铺
		ShopShopsPayMethod shopShopsPayMethod = new ShopShopsPayMethod();// 店铺支付方式
		ShopShopsPayType shopShopsPayType = new ShopShopsPayType(); // 店铺支付单位
		ShopShopsPayTypeStageNum shopShopsPayTypeStageNum = new ShopShopsPayTypeStageNum();// 店铺分期数	
		Date date = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String format = df.format(date);
		Date datee = new Date();
		datee = df.parse(format);
		for (Object obj : map.keySet()) {
			shopShops.setShopName((String) map.get("shopName"));
			shopShops.setLinkMan((String) map.get("linkMan"));
			shopShops.setMobile((String) map.get("mobile"));
			shopShops.setAddress((String) map.get("address"));
			shopShops.setBanner((String)map.get("shopsImg"));
		}
		shopShops.setShopStatus(ShopShopsWithBLOBs.SHOP_STATUS_OK);
		shopShops.setCheckStatus(ShopShopsWithBLOBs.CHECK_STATUS_PASS);
		shopShops.setCreateUserId(jwtInfo.getId());
		shopShops.setCreateTime(datee);
		shopShopsBiz.appendShopShops(shopShops);
		
		List<ShopGoodsGroupRecomm> selectByShopId = goodsGroupRecommService.selectByShopId(shopShops.getShopId());

		if (selectByShopId.size() == 0 || selectByShopId == null) {
			List<ShopGoodsGroupRecomm> shopGoodsGroupRecommList = new ArrayList<ShopGoodsGroupRecomm>();
			for (int i = 1; i <= 10; i++) {
				ShopGoodsGroupRecomm shopGoodsGroupRecomm = new ShopGoodsGroupRecomm();
				shopGoodsGroupRecomm.setRecommStatus(0);
				shopGoodsGroupRecomm.setOrderLevel(i);
				shopGoodsGroupRecomm.setRecommPosId(1);
				shopGoodsGroupRecomm.setCreateUserId(jwtInfo.getId());
				shopGoodsGroupRecomm.setCreateTime(new Date());
				shopGoodsGroupRecomm.setMerchantId(1);
				shopGoodsGroupRecomm.setShopId(shopShops.getShopId());
				shopGoodsGroupRecommList.add(shopGoodsGroupRecomm);
			}
				goodsGroupRecommService.addList(shopGoodsGroupRecommList);
		}
		

		String regionPlay = (String) map.get("regionPlay");
		if (regionPlay == "" || regionPlay.equals("")) {
		} else {
			shopShopsPayMethod.setShopId(shopShops.getShopId());
			shopShopsPayMethod.setCreateTime(datee);
			shopShopsPayMethod.setCreateUserId(jwtInfo.getId());

			shopShopsPayType.setCreateTime(datee);
			shopShopsPayType.setCreateUserId(jwtInfo.getId());
			shopShopsPayType.setShopId(shopShops.getShopId());
			List<String> typeList = (List<String>) map.get("typePlay");
			if (regionPlay.equals("10") || regionPlay == "10") {
				ApiRestResponse<PicklistApi> selectByCodeVal = iParamPickListService.selectByCodeVal("shopPayMethod",
						"10");
				PicklistApi picklistApi = selectByCodeVal.getData();
				shopShopsPayMethod.setPayMethodName(picklistApi.getPicklistText());
				shopShopsPayMethod.setPayMethod(Integer.valueOf(regionPlay));
				shopShopsPayMethodBiz.addShopShopsPayMethod(shopShopsPayMethod);
				if (typeList.size() != 0 || typeList != null) {
					shopShopsPayType.setPayTypeId(null);
					shopShopsPayType.setPayMethodId(shopShopsPayMethod.getPayMethodId());
					if (typeList.size() == 1) {
						if (typeList.get(0).equals("1")) {
							ApiRestResponse<PicklistApi> selectByCodeVal_bank = iParamPickListService
									.selectByCodeVal("shopPayTypeStageBank", "1");
							PicklistApi picklistApi_bank = selectByCodeVal_bank.getData();
							String typees = typeList.get(0);
							shopShopsPayType.setPayType(Integer.valueOf(typees));
							shopShopsPayType.setPayTypeName(picklistApi_bank.getPicklistText());
							shopShopsPayTypeBiz.addShopShopsPayType(shopShopsPayType);

							List<String> typee = (List<String>) map.get("typeePlay");
							if (typee.size() != 0 || typee != null) {
								shopShopsPayTypeStageNum.setPayTypeId(shopShopsPayType.getPayTypeId());
								shopShopsPayTypeStageNum.setPayMethodId(shopShopsPayMethod.getPayMethodId());
								shopShopsPayTypeStageNum.setShopId(shopShops.getShopId());
								shopShopsPayTypeStageNum.setCreateTime(datee);
								shopShopsPayTypeStageNum.setCreateUserId(jwtInfo.getId());
								for (String typeNum : typee) {
									if (typeNum.equals("12")) {
										ApiRestResponse<PicklistApi> selectByCodeVal_Num = iParamPickListService
												.selectByCodeVal("shopPayTypeStageNum", "12");
										PicklistApi picklistApi_Num = selectByCodeVal_Num.getData();
										shopShopsPayTypeStageNum.setStageNumName(picklistApi_Num.getPicklistText());
										shopShopsPayTypeStageNum.setStageNum(Integer.valueOf(typeNum));
										shopShopsPayTypeStageNumBiz
												.addShopShopsPayTypeStageNum(shopShopsPayTypeStageNum);
									}
									if (typeNum.equals("24")) {
										ApiRestResponse<PicklistApi> selectByCodeVal_Num = iParamPickListService
												.selectByCodeVal("shopPayTypeStageNum", "24");
										PicklistApi picklistApi_Num = selectByCodeVal_Num.getData();
										shopShopsPayTypeStageNum.setStageNumName(picklistApi_Num.getPicklistText());
										shopShopsPayTypeStageNum.setStageNum(Integer.valueOf(typeNum));
										shopShopsPayTypeStageNumBiz
												.addShopShopsPayTypeStageNum(shopShopsPayTypeStageNum);
									}
									if (typeNum.equals("6")) {
										ApiRestResponse<PicklistApi> selectByCodeVal_Num = iParamPickListService
												.selectByCodeVal("shopPayTypeStageNum", "6");
										PicklistApi picklistApi_Num = selectByCodeVal_Num.getData();
										shopShopsPayTypeStageNum.setStageNumName(picklistApi_Num.getPicklistText());
										shopShopsPayTypeStageNum.setStageNum(Integer.valueOf(typeNum));
										shopShopsPayTypeStageNumBiz
												.addShopShopsPayTypeStageNum(shopShopsPayTypeStageNum);
									}
									if (typeNum.equals("36")) {
										ApiRestResponse<PicklistApi> selectByCodeVal_Num = iParamPickListService
												.selectByCodeVal("shopPayTypeStageNum", "36");
										PicklistApi picklistApi_Num = selectByCodeVal_Num.getData();
										shopShopsPayTypeStageNum.setStageNumName(picklistApi_Num.getPicklistText());
										shopShopsPayTypeStageNum.setStageNum(Integer.valueOf(typeNum));
										shopShopsPayTypeStageNumBiz
												.addShopShopsPayTypeStageNum(shopShopsPayTypeStageNum);
									}

								}
							}
						}

					}
				}
			} else if (regionPlay.equals("1") || regionPlay == "1") {
				ApiRestResponse<PicklistApi> selectByCodeVal = iParamPickListService.selectByCodeVal("shopPayMethod",
						"1");
				PicklistApi picklistApi = selectByCodeVal.getData();
				shopShopsPayMethod.setPayMethodName(picklistApi.getPicklistText());
				shopShopsPayMethod.setPayMethod(Integer.valueOf(regionPlay));
				shopShopsPayMethodBiz.addShopShopsPayMethod(shopShopsPayMethod);
				if (typeList.size() != 0 || typeList != null) {
					if (typeList.size() == 2) {
						for (String str : typeList) {
							if (str.equals("2")) {
								ApiRestResponse<PicklistApi> selectByCodeVal_line = iParamPickListService
										.selectByCodeVal("shopPayMethodOnLine", "2");
								PicklistApi picklistApi_line = selectByCodeVal_line.getData();
								shopShopsPayType.setPayMethodId(shopShopsPayMethod.getPayMethodId());
								shopShopsPayType.setPayTypeId(null);
								shopShopsPayType.setPayType(Integer.valueOf(str));
								shopShopsPayType.setPayTypeName(picklistApi_line.getPicklistText());
								shopShopsPayTypeBiz.addShopShopsPayType(shopShopsPayType);
							}
							if (str.equals("1")) {
								ApiRestResponse<PicklistApi> selectByCodeVal_line = iParamPickListService
										.selectByCodeVal("shopPayMethodOnLine", "1");
								PicklistApi picklistApi_line = selectByCodeVal_line.getData();
								shopShopsPayType.setPayMethodId(shopShopsPayMethod.getPayMethodId());
								shopShopsPayType.setPayTypeId(null);
								shopShopsPayType.setPayType(Integer.valueOf(str));
								shopShopsPayType.setPayTypeName(picklistApi_line.getPicklistText());
								shopShopsPayTypeBiz.addShopShopsPayType(shopShopsPayType);
							}
						}

					} else if (typeList.size() == 1) {
						String type = typeList.get(0);
						if (type.equals("2")) {
							ApiRestResponse<PicklistApi> selectByCodeVal_line = iParamPickListService
									.selectByCodeVal("shopPayMethodOnLine", "2");
							PicklistApi picklistApi_line = selectByCodeVal_line.getData();
							shopShopsPayType.setPayMethodId(shopShopsPayMethod.getPayMethodId());
							shopShopsPayType.setPayTypeId(null);
							shopShopsPayType.setPayType(Integer.valueOf(type));
							shopShopsPayType.setPayTypeName(picklistApi_line.getPicklistText());
							shopShopsPayTypeBiz.addShopShopsPayType(shopShopsPayType);
						} else if (type.equals("1")) {
							ApiRestResponse<PicklistApi> selectByCodeVal_line = iParamPickListService
									.selectByCodeVal("shopPayMethodOnLine", "1");
							PicklistApi picklistApi_line = selectByCodeVal_line.getData();
							shopShopsPayType.setPayMethodId(shopShopsPayMethod.getPayMethodId());
							shopShopsPayType.setPayTypeId(null);
							shopShopsPayType.setPayType(Integer.valueOf(type));
							shopShopsPayType.setPayTypeName(picklistApi_line.getPicklistText());
							shopShopsPayTypeBiz.addShopShopsPayType(shopShopsPayType);
						}
					}
				}

			}
		}
	}

	@Override
	public ShopShops selectByPrimaryKey(Integer id) throws Exception {

		return shopShopsBiz.selectById(id);
	}

	@Override
	public void updateShopShops(String token, Map map) throws Exception {
		IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
		ShopShops shopShops = new ShopShops();
		Integer shopId = null;
		for (Object obj : map.keySet()) {
			shopId = (Integer) map.get("shopId");
			shopShops.setShopId(shopId);
			shopShops.setShopName((String) map.get("shopName"));
			shopShops.setMobile((String) map.get("mobile"));
			shopShops.setLinkMan((String) map.get("linkMan"));
			shopShops.setAddress((String) map.get("address"));
		}
		List<String> imgsList = (List<String>) map.get("shopsImg");
		shopShops.setBanner(imgsList.get(0));
		shopShopsBiz.updatendShopShops(shopShops);
		String methodPay = (String) map.get("regionPlay");
		List<String> typePlayList = (List<String>) map.get("typePlay"); // 支付单位
		List<String> typePlaySumList = (List<String>) map.get("typeePlay");
		ShopShopsPayMethod shopShopsPayMethod = new ShopShopsPayMethod();// 店铺支付方式
		ShopShopsPayTypeStageNum shopShopsPayTypeStageNum = new ShopShopsPayTypeStageNum();// 店铺分期数
		Date date = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String format = df.format(date);
		Date datee = new Date();
		datee = df.parse(format);
		ShopShopsPayMethod insertShopShopsPMe = shopShopsPayMethodBiz.sleectByShopsId(shopId);
		if (!methodPay.equals("") || methodPay != null) {
			shopShopsPayMethod.setModifyTime(datee);
			shopShopsPayMethod.setModifyUserId(jwtInfo.getId());
			shopShopsPayMethod.setShopId(shopId);
			if (methodPay.equals("10")) {
				ApiRestResponse<PicklistApi> selectByCodeVal_method = iParamPickListService
						.selectByCodeVal("shopPayMethod", "10");
				PicklistApi picklistApi_method = selectByCodeVal_method.getData();
				shopShopsPayMethod.setPayMethodName(picklistApi_method.getPicklistText());
				shopShopsPayMethod.setPayMethod(Integer.valueOf(methodPay));
				shopShopsPayMethodBiz.updateShopShopsPayMethod(shopShopsPayMethod);
				// 分期付
				if (typePlayList.size() != 0 || typePlayList != null) {
					shopShopsPayTypeBiz.deleteShopShopsPayType(shopId);
					// 建行分期付
					for (String playTypeStr : typePlayList) {
						if (playTypeStr.equals("1")) {
							ShopShopsPayType shopShopsPayType = new ShopShopsPayType(); // 店铺支付单位
							shopShopsPayType.setCreateTime(datee);
							shopShopsPayType.setCreateUserId(jwtInfo.getId());
							shopShopsPayType.setModifyTime(datee);
							shopShopsPayType.setModifyUserId(jwtInfo.getId());
							shopShopsPayType.setPayMethodId(insertShopShopsPMe.getPayMethodId());
							shopShopsPayType.setShopId(shopId);
							ApiRestResponse<PicklistApi> selectByCodeVal_Bank = iParamPickListService
									.selectByCodeVal("shopPayTypeStageBank", "1");
							PicklistApi picklistApi_Bank = selectByCodeVal_Bank.getData();
							shopShopsPayType.setPayType(Integer.valueOf(playTypeStr));
							shopShopsPayType.setPayTypeName(picklistApi_Bank.getPicklistText());
							shopShopsPayTypeBiz.addShopShopsPayType(shopShopsPayType);
							if (typePlaySumList.size() != 0 || typePlaySumList != null) {
								shopShopsPayTypeStageNumBiz.deleteShopShopsPayTypeStageNum(shopId);
								shopShopsPayTypeStageNum.setCreateTime(datee);
								shopShopsPayTypeStageNum.setCreateUserId(jwtInfo.getId());
								shopShopsPayTypeStageNum.setModifyTime(datee);
								shopShopsPayTypeStageNum.setModifyUserId(jwtInfo.getId());
								shopShopsPayTypeStageNum.setShopId(shopId);
								shopShopsPayTypeStageNum.setPayMethodId(insertShopShopsPMe.getPayMethodId());
								shopShopsPayTypeStageNum.setPayTypeId(shopShopsPayType.getPayTypeId());
								for (String typeNum : typePlaySumList) {
									if (typeNum.equals("12")) {
										ApiRestResponse<PicklistApi> selectByCodeVal_Num = iParamPickListService
												.selectByCodeVal("shopPayTypeStageNum", "12");
										PicklistApi picklistApi_Num = selectByCodeVal_Num.getData();
										shopShopsPayTypeStageNum.setStageNumName(picklistApi_Num.getPicklistText());
										shopShopsPayTypeStageNum.setStageNum(Integer.valueOf(typeNum));
										shopShopsPayTypeStageNumBiz
												.addShopShopsPayTypeStageNum(shopShopsPayTypeStageNum);
									}
									if (typeNum.equals("24")) {
										ApiRestResponse<PicklistApi> selectByCodeVal_Num = iParamPickListService
												.selectByCodeVal("shopPayTypeStageNum", "24");
										PicklistApi picklistApi_Num = selectByCodeVal_Num.getData();
										shopShopsPayTypeStageNum.setStageNumName(picklistApi_Num.getPicklistText());
										shopShopsPayTypeStageNum.setStageNum(Integer.valueOf(typeNum));
										shopShopsPayTypeStageNumBiz
												.addShopShopsPayTypeStageNum(shopShopsPayTypeStageNum);
									}
									if (typeNum.equals("6")) {
										ApiRestResponse<PicklistApi> selectByCodeVal_Num = iParamPickListService
												.selectByCodeVal("shopPayTypeStageNum", "6");
										PicklistApi picklistApi_Num = selectByCodeVal_Num.getData();
										shopShopsPayTypeStageNum.setStageNumName(picklistApi_Num.getPicklistText());
										shopShopsPayTypeStageNum.setStageNum(Integer.valueOf(typeNum));
										shopShopsPayTypeStageNumBiz
												.addShopShopsPayTypeStageNum(shopShopsPayTypeStageNum);
									}
									if (typeNum.equals("36")) {
										ApiRestResponse<PicklistApi> selectByCodeVal_Num = iParamPickListService
												.selectByCodeVal("shopPayTypeStageNum", "36");
										PicklistApi picklistApi_Num = selectByCodeVal_Num.getData();
										shopShopsPayTypeStageNum.setStageNumName(picklistApi_Num.getPicklistText());
										shopShopsPayTypeStageNum.setStageNum(Integer.valueOf(typeNum));
										shopShopsPayTypeStageNumBiz
												.addShopShopsPayTypeStageNum(shopShopsPayTypeStageNum);
									}

								}
							}
						}
					}
				}
				if (typePlayList.size() == 0 || typePlayList == null) {
					shopShopsPayTypeBiz.deleteShopShopsPayType(shopId);
					shopShopsPayTypeStageNumBiz.deleteShopShopsPayTypeStageNum(shopId);
				}
			} else if (methodPay.equals("1")) {
				// 在线支付
				ApiRestResponse<PicklistApi> selectByCodeVal_method = iParamPickListService
						.selectByCodeVal("shopPayMethod", "1");
				PicklistApi picklistApi_method = selectByCodeVal_method.getData();
				shopShopsPayMethod.setPayMethodName(picklistApi_method.getPicklistText());
				shopShopsPayMethod.setPayMethod(Integer.valueOf(methodPay));
				shopShopsPayMethodBiz.updateShopShopsPayMethod(shopShopsPayMethod);
				if (typePlayList.size() != 0 || typePlayList != null) {
					ShopShopsPayType shopShopsPayTypees = new ShopShopsPayType();
					shopShopsPayTypeBiz.deleteShopShopsPayType(shopId);
					shopShopsPayTypeStageNumBiz.deleteShopShopsPayTypeStageNum(shopId);
					shopShopsPayTypees.setCreateTime(datee);
					shopShopsPayTypees.setCreateUserId(jwtInfo.getId());
					shopShopsPayTypees.setModifyTime(datee);
					shopShopsPayTypees.setModifyUserId(jwtInfo.getId());
					shopShopsPayTypees.setPayMethodId(insertShopShopsPMe.getPayMethodId());
					shopShopsPayTypees.setShopId(shopId);
					if (typePlayList.size() == 2) {
						for (String typePay : typePlayList) {
							if (typePay.equals("1")) {
								ApiRestResponse<PicklistApi> selectByCodeVal_PayType = iParamPickListService
										.selectByCodeVal("shopPayMethodOnLine", "1");
								PicklistApi picklistApi_PayType = selectByCodeVal_PayType.getData();
								shopShopsPayTypees.setPayType(Integer.valueOf(typePay));
								shopShopsPayTypees.setPayTypeId(null);
								shopShopsPayTypees.setPayTypeName(picklistApi_PayType.getPicklistText());
								shopShopsPayTypeBiz.addShopShopsPayType(shopShopsPayTypees);
							}
							if (typePay.equals("2")) {
								ApiRestResponse<PicklistApi> selectByCodeVal_PayType = iParamPickListService
										.selectByCodeVal("shopPayMethodOnLine", "2");
								PicklistApi picklistApi_PayType = selectByCodeVal_PayType.getData();
								shopShopsPayTypees.setPayType(Integer.valueOf(typePay));
								shopShopsPayTypees.setPayTypeId(null);
								shopShopsPayTypees.setPayTypeName(picklistApi_PayType.getPicklistText());
								shopShopsPayTypeBiz.addShopShopsPayType(shopShopsPayTypees);
							}
						}
					} else if (typePlayList.size() == 1) {
						String payType = typePlayList.get(0);
						if (payType.equals("1")) {
							ApiRestResponse<PicklistApi> selectByCodeVal_PayType = iParamPickListService
									.selectByCodeVal("shopPayMethodOnLine", "1");
							PicklistApi picklistApi_PayType = selectByCodeVal_PayType.getData();
							shopShopsPayTypees.setPayType(Integer.valueOf(payType));
							shopShopsPayTypees.setPayTypeId(null);
							shopShopsPayTypees.setPayTypeName(picklistApi_PayType.getPicklistText());
							shopShopsPayTypeBiz.addShopShopsPayType(shopShopsPayTypees);
						} else if (payType.equals("2")) {
							ApiRestResponse<PicklistApi> selectByCodeVal_PayType = iParamPickListService
									.selectByCodeVal("shopPayMethodOnLine", "2");
							PicklistApi picklistApi_PayType = selectByCodeVal_PayType.getData();
							shopShopsPayTypees.setPayType(Integer.valueOf(payType));
							shopShopsPayTypees.setPayTypeId(null);
							shopShopsPayTypees.setPayTypeName(picklistApi_PayType.getPicklistText());
							shopShopsPayTypeBiz.addShopShopsPayType(shopShopsPayTypees);
						}
					}
				}
				if (typePlayList.size() == 0 || typePlayList == null) {
					shopShopsPayTypeBiz.deleteShopShopsPayType(shopId);
					shopShopsPayTypeStageNumBiz.deleteShopShopsPayTypeStageNum(shopId);
				}
			}
		}
	}
}
